//
//  FR_HistoryViewController.m
//  FaceRecognition
//
//  Created by Sylar on 2016/11/28.
//  Copyright © 2016年 Sylar. All rights reserved.
//

#import "FR_HistoryViewController.h"
#import "FR_SearchRecordViewController.h"
#import "FR_StudentRecordList_ViewController.h"
#import "FR_Record_InformationViewController.h"

#import "FR_HistoryRecordCell.h"
#import "FR_StudentRecordCell.h"

#import "FR_StudentRecode_Model.h"
#import "FR_HistoryRecord_Model.h"

@interface FR_HistoryViewController ()<UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate>
{
    UIView *topView;
    UIButton *opButton;
    UIView *shadowView;
    
    NSMutableArray *topViewArr;
    
    NSInteger lastType;
    
    UIButton *imgBtn;
    
    NSString *classid;
    
}


@property (nonatomic, strong) UITableView  *historyTable;
@property (nonatomic, strong) UITableView  *stuRecordTable;
@property (nonatomic, strong) UIImageView  *navBackView;
@property (nonatomic, strong) UILabel      *navTitlelabel;
@property (nonatomic, strong) UITableView  *classesTable;
@property (nonatomic, strong) UIView       *backView;;
@property (nonatomic, strong) UILabel      *nohisLabel;
@property (nonatomic, strong) UILabel      *nostuLabel;
@property (nonatomic, strong) UIImageView  *classArrow;


@property (nonatomic, strong) NSMutableArray *historyArr;
@property (nonatomic, strong) NSMutableArray *stuRecordArr;
@property (nonatomic, strong) NSMutableArray *classesArr;
@property (nonatomic, strong) NSMutableArray *classNames;

@property (nonatomic, assign) NSInteger hisPage;
@property (nonatomic, assign) NSInteger stuPage;


@end

@implementation FR_HistoryViewController

- (id)init
{
    self = [super init];
    if (self) {
        
        //self.hidesBottomBarWhenPushed = NO;
        
    }
    return self;
}

- (void)loadView {
    
    [super loadView];
    
    [self.view setBackgroundColor:colorFromHex(@"#F5F8FA")];
    
   self.navBar.rightButton.hidden = NO;
   self.navBar.rightImg.hidden =NO;
   self.navBar.rightImg.image =[UIImage imageNamed:@"record_head_search_"] ;
   [self.navBar.rightButton addTarget:self action:@selector(searchAction) forControlEvents:UIControlEventTouchUpInside];
   
   self.navBar.centerImg.hidden = NO;
   self.navBackView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 120, 44)];
   self.navBackView.userInteractionEnabled=YES;
   
   self.navTitlelabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 8,120, 18)];
   self.navTitlelabel.textAlignment = NSTextAlignmentCenter;
   self.navTitlelabel.font = [UIFont boldSystemFontOfSize:18];
   self.navTitlelabel.textColor = colorFromHex(@"3b3b3b");
   self.navTitlelabel.centerX = 60;
   
   [self.navBackView addSubview:self.navTitlelabel];
   
   
   
   imgBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
   [imgBtn setFrame:CGRectMake(0, 0, 120, 44)];
   imgBtn.hidden = YES;
   [imgBtn addTarget:self action:@selector(chooseClass) forControlEvents:(UIControlEventTouchUpInside)];
   [self.navBackView addSubview:imgBtn];
   
   [self.navBar.centerImg addSubview:self.navBackView];
   
   self.hisPage = 1;
   self.stuPage = 1;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    lastType =[SYAccountTool ShareAccount].account.lasttype;
    
    [self setUpTopView];
    [self setUpTableView];
    //[self loadAllClasses];
    [self Java_getClasses];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Method

- (void)setUpTopView {
    
    topViewArr = [[NSMutableArray alloc]init];
    
    int count = 2;
    
    for (int i = 0; i < count; i++) {
        
        topView = [[UIView alloc]initWithFrame:CGRectMake(i*(SCREENWIDTH/count), SafeAreaTopHeight, SCREENWIDTH/count, 45)];
        topView.tag = i+50;
        [topView setBackgroundColor:[UIColor whiteColor]];
        
        [self.view addSubview:topView];
        
        shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 43, SCREENWIDTH/count, 2)];
        [shadowView setBackgroundColor:DEFAULTCOLOR];
        shadowView.tag = i + 51;
        [topView addSubview:shadowView];
        
        [topViewArr addObject:topView];
        
        
        opButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH/count, 45)];
        [opButton.titleLabel setFont:[UIFont systemFontOfSize:17]];
        opButton.tag = i+52;
        [opButton setTitleColor:DEFAULTCOLOR forState:(UIControlStateSelected)];
        [opButton setTitleColor:RGBCOLOR(221, 221, 221) forState:(UIControlStateNormal)];
        [topView addSubview:opButton];
        
        if (i == 0) {
            [opButton addTarget:self action:@selector(historyAction:) forControlEvents:(UIControlEventTouchUpInside)];
            
            [opButton setTitle:@"历史记录" forState:(UIControlStateNormal)];
            
        }else if (i == 1){
            [opButton addTarget:self action:@selector(stuRecordAction:) forControlEvents:(UIControlEventTouchUpInside)];
            
            [opButton setTitle:@"宝宝记录" forState:(UIControlStateNormal)];
            
        }
    }
    
    //默认选择历史记录
    [self displayTopView:50];
}

- (void)displayTopView:(NSInteger )tag {
    
    for (UIView *view in topViewArr) {
        if (view.tag != tag) {
            
            UIButton *btn = (UIButton *)[view viewWithTag:view.tag+2];
            btn.selected = NO;
            
            UIView *shadow = (UIView *)[view viewWithTag:view.tag+1];
            [shadow setBackgroundColor:[UIColor clearColor]];
        }else {
            
            UIButton *btn = (UIButton *)[view viewWithTag:view.tag+2];
            btn.selected = YES;
            
            UIView *shadow = (UIView *)[view viewWithTag:view.tag+1];
            [shadow setBackgroundColor:DEFAULTCOLOR];
            
        }
        
    }
}

- (void)setUpTableView {
    
    [self.view addSubview:self.historyTable];
    [self.historyTable setHidden:NO];
    //[self getHistoryRecordData];
    //[self Java_getHistoryRecordData];
    
    [self.view addSubview:self.stuRecordTable];
    [self.stuRecordTable setHidden:YES];
    //[self getStudentRecordData];
    //[self Java_StudentRecord];
}


#pragma mark - TableViewSoureData

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (tableView == self.classesTable) {
        return [self.classesArr count];
    }else if (tableView == self.historyTable) {
        return [self.historyArr count];
    }else if (tableView == self.stuRecordTable) {
        return [self.stuRecordArr count];
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (tableView == self.classesTable) {
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"classIdentifier"];
        
        
        
        if (cell == nil) {
            cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"classIdentifier"];
            
            UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 43.5, SCREENWIDTH, 0.5)];
            [lineView setBackgroundColor:colorFromHex(@"#DEDEDE")];
            [cell.contentView addSubview:lineView];
            
        }
        
        for (UIView *view in cell.contentView.subviews) {
            if (view.tag == 50) {
                [view removeFromSuperview];
            }
        }
        UILabel *className = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 44)];
        [className setFont:[UIFont systemFontOfSize:16]];
        [className setTextColor:colorFromHex(@"#3b3b3b")];
        className.textAlignment = NSTextAlignmentCenter;
        className.tag = 50;
        
        [cell.contentView addSubview:className];
        
        className.text = [self.classNames objectAtIndex:indexPath.row];
        
        return cell;
        
    }else if (tableView == self.historyTable) {
        
        FR_HistoryRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"hisIdentifier"];
        if (cell == nil) {
            cell = [[FR_HistoryRecordCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"hisIdentifier"];
        }
        
        FR_HistoryRecord_Model *model = [self.historyArr objectAtIndex:indexPath.row];
        
        [cell creatCell:model object:1];
        
        return cell;
        
    }else if (tableView == self.stuRecordTable) {
        
        FR_StudentRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"stuIdentifier"];
        if (cell == nil) {
            cell = [[FR_StudentRecordCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"stuIdentifier"];
        }
        
        FR_StudentRecode_Model *model = [self.stuRecordArr objectAtIndex:indexPath.row];
        
        [cell creatCell:model];
        
        return cell;
        
        
    }
    return nil;
}

#pragma mark - TableViewDelagate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (tableView == self.classesTable) {
        
        classid = [[self.classesArr objectAtIndex:indexPath.row] objectForKey:@"classid"];
        
        NSString *titleStr = [self.classNames objectAtIndex:indexPath.row];
        self.navTitlelabel.text = titleStr;
        [self.navTitlelabel setWidth:[titleStr length]*19 > 152 ? 152 :[titleStr length]*19];
        self.navTitlelabel.centerX = 60;
        
        [self.classArrow setImage:[UIImage imageNamed:@"record_head_classchoose_down_"]];
        
        [self.backView setHidden:YES];
        [self.classesTable setHidden:YES];
        
        [self displayTopView:50];
        
        [self Java_getHistoryRecordData];
        [self Java_StudentRecord];
        
        self.historyTable.scrollsToTop = YES;
        self.stuRecordTable.scrollsToTop = YES;
        
        self.historyTable.hidden = NO;
        self.stuRecordTable.hidden = YES;
        
    }else if (tableView == self.historyTable) {
        FR_Record_InformationViewController *infoVC = [[FR_Record_InformationViewController alloc]init];
        infoVC.recordType = 0;
        FR_HistoryRecord_Model *model = [self.historyArr objectAtIndex:indexPath.row];
        
        infoVC.recordModel = model;
        [self.navigationController pushViewController:infoVC animated:YES];
        
    }else if (tableView == self.stuRecordTable) {
        FR_StudentRecordList_ViewController *listVC = [[FR_StudentRecordList_ViewController alloc]init];
        FR_StudentRecode_Model *model = [self.stuRecordArr objectAtIndex:indexPath.row];
        listVC.faceuserid = [NSString stringWithFormat:@"%ld",(long)model.faceuserid];
        listVC.userid = [NSString stringWithFormat:@"%ld",(long)model.userid];
        listVC.classId = [NSString stringWithFormat:@"%ld",(long)model.classid];
        listVC.recordType = 0;
        [self.navigationController pushViewController:listVC animated:YES];
        
    }
}

#pragma mark - Action



- (void)searchAction {
    
    FR_SearchRecordViewController *searchVC = [[FR_SearchRecordViewController alloc]init];
    searchVC.classID = classid;
    searchVC.searchType = 0;
    [self.navigationController pushViewController:searchVC animated:YES];
}

- (void)chooseClass {
    
    if (self.classesTable.hidden == YES) {
        [self.classesTable setHidden:NO];
        [self.backView setHidden:NO];
        [self.classArrow setImage:[UIImage imageNamed:@"record_head_classchoose_up_"]];
    }else {
        [self.classesTable setHidden:YES];
        [self.backView setHidden:YES];
        [self.classArrow setImage:[UIImage imageNamed:@"record_head_classchoose_down_"]];
    }
    
}

- (void)removeClassTable {
    [self.classesTable setHidden:YES];
    [self.backView setHidden:YES];
    [self.classArrow setImage:[UIImage imageNamed:@"record_head_classchoose_down_"]];
}

- (IBAction)historyAction:(id)sender {
    
    UIButton *btn = (UIButton *)sender;
    
    [self displayTopView:btn.tag-2];
    
    self.historyTable.hidden = NO;
    self.stuRecordTable.hidden = YES;
    
}

- (IBAction)stuRecordAction:(id)sender {
    
    UIButton *btn = (UIButton *)sender;
    
    [self displayTopView:btn.tag-2];
    
    self.historyTable.hidden = YES;
    self.stuRecordTable.hidden = NO;
    
}

#pragma mark - Request 

- (void)Java_getClasses {
    
    NSMutableDictionary *paramDic = [[NSMutableDictionary alloc]init];
    [paramDic setObject:USERID forKey:@"teacherid"];
    [paramDic setObject:SCHOOLID forKey:@"scid"];
    [paramDic setObject:[SYAccountTool ShareAccount].account.schoolManage > 0?@"1":@"0" forKey:@"type"];
    
    [Utils Java_get:@"api/getTeacherClass" parameters:paramDic success:^(NSInteger recode, id jsonObject) {
        
        NSArray *arr = [jsonObject objectForKey:@"re_data"];
        
        if (arr.count == 0) {  //没有班级
            
            NSString *message;
            if (lastType == 1) {
                
                message = @"请先创建/加入班级";
            }else if (lastType ==2){
                
                message = @"请先加入班级";
            }
            
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil,nil];
            
            alert.tag = 101;
            [alert show];
            
        }else if(arr.count > 0){ //有班级
            
            [self.classesArr addObjectsFromArray:arr];
            
            for (NSDictionary *dic in arr) {
                
                NSString *className = [dic objectForKey:@"classname"];
                
                [self.classNames addObject:className];
                
            }
            
            NSDictionary *classInfo = [self.classesArr objectAtIndex:0];
            classid = [NSString stringWithFormat:@"%@",[classInfo objectForKey:@"classid"]];
            
            if (arr.count > 1) {
                self.classArrow = [[UIImageView alloc]initWithFrame:CGRectMake(52.5, self.navTitlelabel.bottom+2, 15, 11)];
                [self.classArrow setImage:[UIImage imageNamed:@"record_head_classchoose_down_"]];
                
                [self.navBackView addSubview:self.classArrow];
                
                self->imgBtn.hidden = NO;
            }
            
            NSString *titleStr = [self.classNames objectAtIndex:0];
            self.navTitlelabel.text = titleStr;
            [self.navTitlelabel setWidth:[titleStr length]*19 > 152 ? 152 :[titleStr length]*19];
            self.navTitlelabel.centerX = 60;
            
            
            [self.view addSubview:self.backView];
            [self.view addSubview:self.classesTable];
            
            if (44*self.classNames.count > SCREENHEIGH - SafeAreaTopHeight - 44) {
                self.classesTable.scrollEnabled = YES;
                [self.classesTable setHeight:SCREENHEIGH - SafeAreaTopHeight - 44];
            }else {
                
                [self.classesTable setHeight:44 * self.classNames.count];
                self.classesTable.scrollEnabled = NO;
            }
            
            [self.classesTable setHidden:YES];
            [self.backView setHidden:YES];
            
            
//            [self getHistoryRecordData];
//            [self getStudentRecordData];
            
            [self Java_getHistoryRecordData];
            [self Java_StudentRecord];
            
        }
        
    } failure:^(NSInteger recode, NSError *error) {
        
        
        
    }];
}


- (void)loadAllClasses {
    
    NSMutableDictionary * paramDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [paramDic setObject:USERID forKey:@"teacherid"];
    [paramDic setObject:SCHOOLID forKey:@"scid"];
    [paramDic setObject:@"0" forKey:@"type"];
    
    [Utils Java_get:@"api/getTeacherClass" parameters:paramDic success:^(NSInteger recode, id jsonObject) {
        NSArray *arr = [jsonObject objectForKey:@"re_data"];
        
        if (arr.count == 0) {  //没有班级
            
            NSString *message;
            if (lastType == 1) {
                
                message = @"请先创建/加入班级";
            }else if (lastType ==2){
                
                message = @"请先加入班级";
            }
            
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil,nil];
            
            alert.tag = 101;
            [alert show];
            
        }else if(arr.count > 0){ //有班级
            
            [self.classesArr addObjectsFromArray:arr];
            
            for (NSDictionary *dic in arr) {
                
                NSString *className = [dic objectForKey:@"classname"];
                
                [self.classNames addObject:className];
                
            }
            
            NSDictionary *classInfo = [self.classesArr objectAtIndex:0];
            classid = [NSString stringWithFormat:@"%@",[classInfo objectForKey:@"classid"]];
            
            if (arr.count > 1) {
                self.classArrow = [[UIImageView alloc]initWithFrame:CGRectMake(52.5, self.navTitlelabel.bottom+2, 15, 11)];
                [self.classArrow setImage:[UIImage imageNamed:@"record_head_classchoose_down_"]];
                
                [self.navBackView addSubview:self.classArrow];
                
                self->imgBtn.hidden = NO;
            }
            
            NSString *titleStr = [self.classNames objectAtIndex:0];
            self.navTitlelabel.text = titleStr;
            [self.navTitlelabel setWidth:[titleStr length]*19 > 152 ? 152 :[titleStr length]*19];
            self.navTitlelabel.centerX = 100;
            
            
            [self.view addSubview:self.backView];
            [self.view addSubview:self.classesTable];
            
            if (44*self.classNames.count > SCREENHEIGH - 64 - 44) {
                self.classesTable.scrollEnabled = YES;
                [self.classesTable setHeight:SCREENHEIGH - 64 - 44];
            }else {
                
                [self.classesTable setHeight:44 * self.classNames.count];
                self.classesTable.scrollEnabled = NO;
            }
            
            [self.classesTable setHidden:YES];
            [self.backView setHidden:YES];
            
            
//            [self getHistoryRecordData];
//            [self getStudentRecordData];
            
            [self Java_getHistoryRecordData];
            [self Java_StudentRecord];
            
        }
        
    } failure:^(NSInteger recode, NSError *error) {
        
    }];
    
    /*
    NSMutableDictionary * paramDic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [paramDic setObject:@"sy_rollcall_classlist" forKey:@"method"];
    [paramDic setObject:USERID forKey:@"teacherid"];
    
    [Utils get:nil parameters:paramDic success:^(NSInteger recode, id jsonObject) {
        
        NSArray *arr = [jsonObject objectForKey:@"re_data"];
        
        if (arr.count == 0) {  //没有班级
            
            NSString *message;
            if (lastType == 1) {
                
                message = @"请先创建/加入班级";
            }else if (lastType ==2){
                
                message = @"请先加入班级";
            }
            
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil,nil];
            
            alert.tag = 101;
            [alert show];
            
        }else if(arr.count > 0){ //有班级
            
            [self.classesArr addObjectsFromArray:arr];
            
            for (NSDictionary *dic in arr) {
                
                NSString *className = [dic objectForKey:@"classname"];
                
                [self.classNames addObject:className];
                
            }
            
            NSDictionary *classInfo = [self.classesArr objectAtIndex:0];
            classid = [NSString stringWithFormat:@"%@",[classInfo objectForKey:@"classid"]];
            
            if (arr.count > 1) {
                self.classArrow = [[UIImageView alloc]initWithFrame:CGRectMake(92.5, self.navTitlelabel.bottom+2, 15, 11)];
                [self.classArrow setImage:[UIImage imageNamed:@"record_head_classchoose_down_"]];
                
                [self.navBackView addSubview:self.classArrow];
                
                self->imgBtn.hidden = NO;
            }
            
            NSString *titleStr = [self.classNames objectAtIndex:0];
            self.navTitlelabel.text = titleStr;
            [self.navTitlelabel setWidth:[titleStr length]*19 > 152 ? 152 :[titleStr length]*19];
            self.navTitlelabel.centerX = 100;
            
            
            [self.view addSubview:self.backView];
            [self.view addSubview:self.classesTable];
            
            if (44*self.classNames.count > SCREENHEIGH - 64 - 44) {
                self.classesTable.scrollEnabled = YES;
                [self.classesTable setHeight:SCREENHEIGH - 64 - 44];
            }else {
                
                [self.classesTable setHeight:44 * self.classNames.count];
                self.classesTable.scrollEnabled = NO;
            }
            
            [self.classesTable setHidden:YES];
            [self.backView setHidden:YES];
            
            
            [self getHistoryRecordData];
            [self getStudentRecordData];
            
            [self Java_testRequest];
            [self Java_StudentRecord];
            
        }
        
    } failure:^(NSInteger recode, NSError *error) {
        
    }];
     */
    
}

- (void)Java_getHistoryRecordData {
    
    NSMutableDictionary *paramDic = [[NSMutableDictionary alloc]init];
    [paramDic setObject:classid forKey:@"classid"];
    [paramDic setObject:@"20" forKey:@"pagesize"];
    [paramDic setObject:@"1" forKey:@"pageno"];
    [paramDic setObject:[SYAccountTool ShareAccount].account.scid forKey:@"scid"];
    
    [Utils Java_get:@"api/getClassStuParEventHis" parameters:paramDic success:^(NSInteger recode, id jsonObject) {
        
        NSArray *arr = [jsonObject objectForKey:@"re_data"];
        
        self.hisPage = 1;//重置分页
        self.historyArr = [[NSMutableArray alloc]init];
        
        if (arr.count > 0) {
            
            for (NSDictionary *dic in arr) {
                
                FR_HistoryRecord_Model *model = [FR_HistoryRecord_Model mj_objectWithKeyValues:dic];
                
                [self.historyArr addObject:model];
            }
            self.nohisLabel.hidden = YES;
        }else {
            self.nohisLabel.hidden = NO;
        }
        
        [self.historyTable.mj_header endRefreshing];
        [self.historyTable.mj_footer endRefreshing];
        [self.historyTable reloadData];
        
        
    } failure:^(NSInteger recode, NSError *error) {
        
        
    }];
}


- (void)loadMoreHistoryData {
    
    self.hisPage += 1;
    
    NSMutableDictionary *paramDic = [[NSMutableDictionary alloc]init];
    [paramDic setObject:classid forKey:@"classid"];
    [paramDic setObject:@"20" forKey:@"pagesize"];
    [paramDic setObject:[NSString stringWithFormat:@"%ld",self.hisPage] forKey:@"pageno"];
    [paramDic setObject:[SYAccountTool ShareAccount].account.scid forKey:@"scid"];
    
    [Utils Java_get:@"api/getClassStuParEventHis" parameters:paramDic success:^(NSInteger recode, id jsonObject) {
        
        NSArray *arr = [jsonObject objectForKey:@"re_data"];
        
        if (arr.count > 0) {
            
            for (NSDictionary *dic in arr) {
                
                FR_HistoryRecord_Model *model = [FR_HistoryRecord_Model mj_objectWithKeyValues:dic];
                
                [self.historyArr addObject:model];
            }
            [self.historyTable.mj_footer endRefreshing];
        }else {
            
            [self.historyTable.mj_footer endRefreshingWithNoMoreData];
            self.hisPage -= 1;
        }
        
        
        [self.historyTable reloadData];
        
    }failure:^(NSInteger recode, NSError *error) {
        [self.historyTable.mj_footer endRefreshing];
        self.hisPage -= 1;
    }];
    
    
    
}

- (void)Java_StudentRecord {
    
    NSMutableDictionary *paramDic = [[NSMutableDictionary alloc]init];
    [paramDic setObject:classid forKey:@"classid"];
    [paramDic setObject:@"20" forKey:@"pagesize"];
    [paramDic setObject:@"1" forKey:@"pageno"];
    [paramDic setObject:[SYAccountTool ShareAccount].account.scid forKey:@"scid"];
    
    [Utils Java_get:@"api/getClassStuPicList" parameters:paramDic success:^(NSInteger recode, id jsonObject) {
        
        NSArray *arr = [jsonObject objectForKey:@"re_data"];
        
        self.stuPage = 1;//重置分页
        self.stuRecordArr = [[NSMutableArray alloc]init];
        
        if (arr.count > 0) {
            
            for (NSDictionary *dic in arr) {
                
                FR_StudentRecode_Model *model = [FR_StudentRecode_Model mj_objectWithKeyValues:dic];
                
                [self.stuRecordArr addObject:model];
            }
            self.nostuLabel.hidden = YES;
        }else {
            self.nostuLabel.hidden = NO;
        }
        
        [self.stuRecordTable.mj_header endRefreshing];
        [self.stuRecordTable.mj_footer endRefreshing];
        [self.stuRecordTable reloadData];
        
    } failure:^(NSInteger recode, NSError *error) {
        
        
    }];
}


- (void)loadMoreStudentRecord {
    
    self.stuPage += 1;
    
    NSMutableDictionary *paramDic = [[NSMutableDictionary alloc]init];
    [paramDic setObject:classid forKey:@"classid"];
    [paramDic setObject:@"20" forKey:@"pagesize"];
    [paramDic setObject:[NSString stringWithFormat:@"%ld",(long)self.stuPage] forKey:@"pageno"];
    [paramDic setObject:[SYAccountTool ShareAccount].account.scid forKey:@"scid"];
    
    [Utils Java_get:@"api/getClassStuPicList" parameters:paramDic success:^(NSInteger recode, id jsonObject) {
        NSArray *arr = [jsonObject objectForKey:@"re_data"];
        
        if (arr.count > 0) {
            
            for (NSDictionary *dic in arr) {
                
                FR_StudentRecode_Model *model = [FR_StudentRecode_Model mj_objectWithKeyValues:dic];
                
                [self.stuRecordArr addObject:model];
            }
            [self.stuRecordTable.mj_footer endRefreshing];
        }else {
            
            [self.stuRecordTable.mj_footer endRefreshingWithNoMoreData];
            self.stuPage -= 1;
        }
        
        
        [self.stuRecordTable reloadData];
        
    }failure:^(NSInteger recode, NSError *error) {
        self.stuPage -= 1;
        [self.stuRecordTable.mj_footer endRefreshing];
    }];
    
}




#pragma mark - Get 

- (UITableView *)historyTable {
   
   if (_historyTable == nil) {
      _historyTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 45+10+SafeAreaTopHeight, SCREENWIDTH, SCREENHEIGH - SafeAreaTopHeight-SafeAreaBottomHeight -50-10) style:(UITableViewStylePlain)];
      _historyTable.delegate = self;
      _historyTable.dataSource = self;
      _historyTable.rowHeight = 58;
      _historyTable.separatorStyle = UITableViewCellSeparatorStyleNone;
      _historyTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
         
         [self Java_getHistoryRecordData];
      }];
      _historyTable.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
         
         [self loadMoreHistoryData];
      }];
      
      self.nohisLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 150, SCREENWIDTH, 15)];
      [self.nohisLabel setFont:[UIFont systemFontOfSize:14]];
      [self.nohisLabel setText:@"暂无历史记录"];
      [self.nohisLabel setTextColor:[UIColor colorWithHexString:@"#979797"]];
      self.nohisLabel.textAlignment = NSTextAlignmentCenter;
      self.nohisLabel.hidden = YES;
      
      [_historyTable addSubview:self.nohisLabel];
      
      
      
   }
   return _historyTable;
}

- (UITableView *)stuRecordTable {
   
   if (_stuRecordTable == nil) {
      _stuRecordTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 109+10+ SafeAreaTopHeight - 64, SCREENWIDTH, SCREENHEIGH - SafeAreaTopHeight - SafeAreaBottomHeight-50-10) style:(UITableViewStylePlain)];
      _stuRecordTable.delegate = self;
      _stuRecordTable.dataSource = self;
      _stuRecordTable.rowHeight = 58;
      _stuRecordTable.separatorStyle = UITableViewCellSeparatorStyleNone;
      _stuRecordTable.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
         
         [self Java_StudentRecord];
      }];
      _stuRecordTable.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
         
         [self loadMoreStudentRecord];
      }];
      
      self.nostuLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 150, SCREENWIDTH, 15)];
      [self.nostuLabel setFont:[UIFont systemFontOfSize:14]];
      [self.nostuLabel setText:@"暂无宝宝记录"];
      [self.nostuLabel setTextColor:[UIColor colorWithHexString:@"#979797"]];
      self.nostuLabel.textAlignment = NSTextAlignmentCenter;
      self.nostuLabel.hidden = YES;
      
      [_stuRecordTable addSubview:self.nostuLabel];
      
   }
   return _stuRecordTable;
}

- (UITableView *)classesTable {
    
    if (_classesTable == nil) {
        
        _classesTable = [[UITableView alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight, SCREENWIDTH, 0) style:(UITableViewStylePlain)];
        _classesTable.delegate = self;
        _classesTable.dataSource = self;
        _classesTable.rowHeight = 44;
        _classesTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _classesTable;
}

- (UIView *)backView {
    
    if (_backView == nil) {
        _backView = [[UIView alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight, SCREENWIDTH, SCREENHEIGH-SafeAreaTopHeight-SafeAreaBottomHeight)];
        [_backView setBackgroundColor:[UIColor blackColor]];
        _backView.alpha = 0.5;
        
        //[_backView addSubview:self.classesTable];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeClassTable)];
        [_backView addGestureRecognizer:tap];
    }
    return _backView;
}

- (NSMutableArray *)classesArr{
    
    if (_classesArr == nil) {
        
        _classesArr = [NSMutableArray array];
        _classNames = [NSMutableArray array];
    }
    
    return _classesArr;
}
@end
